/**
 * 可选属性
 * 
    interface IPerson {
      name: string;
      age: number;
      sex?: string;
    }

    const p1: IPerson = {
      name: "张三",
      age: 18,
    };
 */

/**
 * 可选属性的检查
    interface IPerson {
      name: string;
      age: number;
      sex?: string;
    }

    function printName(info: IPerson) {
      // info.sex 这时类型为 string | undefined
      //    操作它时要注意判断

      if (info.sex) {
        // 类型收窄
        info.sex.toUpperCase();
      }
    }
 */

/**
 * 只读属性
 *    readonly

      interface IPerson {
        name: string;
        readonly age: number; // 只读
        sex?: string; // 可选
      }

      let p1: IPerson = {
        name: "张三",
        age: 18,
      };

      p1.name = "里斯"; // OK
      p1.age++;
 */

/**
 * 字面量对象类型
 *    { x: number; y: number }
 *    缺点：不好复用
 */

// interface IPOST {
//   x: number;
//   y: number;
// }

// function printCoord(pt: IPOST) {
//   console.log("The coordinate's x value is " + pt.x);
//   console.log("The coordinate's y value is " + pt.y);
// }

// printCoord({ x: 3, y: 7 }); // OK
// printCoord({ x: "3", y: "8" }); // Error 不能将类型“string”分配给类型“number”
